package com.sgb.kjwl.view.ui.fragment.pick;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentPickAttentionDetailBinding;
import com.sgb.auction.fragment.FocusAuctionListFragment;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 智能关注-招采
 */
public class PickAttentionDetailFragment extends AppFragment {

    private FragmentPickAttentionDetailBinding binding;
    private SlidingFragmentPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
//    private String[] titles = new String[]{"招标公告", "竞价采购", "招标信息", "中标公告"};
    private String[] titles = new String[]{"招标公告", "竞价采购", "中标公告"};
    private int position = 0;
    public  boolean isInIt = false;

    public static PickAttentionDetailFragment newInstance() {
        PickAttentionDetailFragment fragment = new PickAttentionDetailFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_pick_attention_detail, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    public void initView() {
        mFragments = new ArrayList<>();

        for (int i = 0; i < titles.length; i++) {
            if (i == 0) {
                mFragments.add(PickAttentionSigningUpListFragment.newInstance());
            } else if (i == 1) {
                mFragments.add(PickAttentionBiddingListFragment.newInstance());
            } else if (i == 2) {
                mFragments.add(PickAttentionNoticingBidFragment.newInstance());
            }
        }

        pagerAdapter = new SlidingFragmentPagerAdapter(getChildFragmentManager(), mFragments, titles);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setCurrentItem(position);
        binding.viewpager.setOffscreenPageLimit(mFragments.size());
        binding.viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int i) {
                position = i;
            }

            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });
        binding.tabLayout.setupWithViewPager(binding.viewpager);
        isInIt = true;
    }
}
